# -*- coding: utf-8 -*-
# @Time : 2021-01-26 22:05
# @File : run.py.py
import concurrent.futures
import os
import pytest
from common.Allure_Report import allure_generate
from config import Conf


# 1、方法实现
def run_pytest(device):
    report_path = Conf.report_path + os.sep + 'result' + os.sep + device['name']
    report_html = Conf.report_path + os.sep + 'html' + os.sep + device['name']
    pytest.main([f"--cmdopt={device}", '--alluredir', report_path])
    allure_generate(report_path, report_html)


# 3、pool并发
def run_pool(devices):
    with concurrent.futures.ProcessPoolExecutor(len(devices)) as executor:
        executor.map(run_pytest, devices)


if __name__ == '__main__':
    # 启动appium自定义参数  host="127.0.0.1", port="4723", bpport="4724", uuid=None
    # 2、定义列表
    devices_list = list()
    # device_1 = {
    #     "host": "127.0.0.1",
    #     "port": "4723",
    #     "bpport": "4724",
    #     "uuid": "192.168.139.5:5555",
    #     "systemPort": "8200",
    #     "name": "Google"
    # }
    device_2 = {
        "host": "192.168.0.104",
        "port": "4723",
        "bpport": "4724",
        "uuid": "59t85dk7h6x45ll7",
        # "systemPort": "8201",
        "name": "RedMi"
    }
    # devices_list.append(device_1)
    devices_list.append(device_2)
    run_pool(devices_list)